import { Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn } from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";
import { CharacterEntity } from "./character.entity";

@Entity("character_residences")
@ManualTimestamp()
export class CharacterResidenceEntity {
  @PrimaryGeneratedColumn()
  id!: number;

  @Column("int", { name: "characterId", unique: true })
  characterId!: number;

  @Column("varchar", { length: 64, comment: "居住地名称" })
  homeName!: string;

  @Column("int", { default: 1, comment: "居住地等级" })
  homeLevel!: number;

  @Column("varchar", { length: 64, nullable: true, comment: "房产名称" })
  houseName!: string;

  @Column("int", { default: 0, comment: "房产等级" })
  houseLevel!: number;

  @Column("varchar", { length: 64, nullable: true, comment: "坐骑名称" })
  horseName!: string;

  @Column("int", { default: 0, comment: "坐骑等级" })
  horseLevel!: number;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;

  @Column("datetime", { name: "updated_at", nullable: true, comment: "更新时间" })
  updated_at!: Date | null;

  // 关联关系
  @OneToOne(() => CharacterEntity, (character) => character.residence)
  @JoinColumn({ name: "characterId" })
  character!: CharacterEntity;
}
